<!doctype html>
<html>
<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable"  content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no">
    
    
    <!--Simple SEO-->

<meta name="description" content=保存一下自己积累的技术资料/>


<meta name="robots" content=all />
<meta name="google" content=all />
<meta name="googlebot" content=all />
<meta name="verify" content=all />
    <!--Title-->

<title>list.sort 方法和内置sorted | 黄龙天空</title>

<link rel="alternate" href="/atom.xml" title="黄龙天空" type="application/atom+xml">


<link rel="icon" href="/favicon.ico">

    
<link rel="stylesheet" href="/css/base.css">
<link rel="stylesheet" href="/css/pages/post.css">
<link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="/css/thirdParty/highlight/github.css">
    <!--script-->




<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>


    
    
</head>

<body>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<style>
    header{ top: 71px; position: absolute!important;}
    #container{padding-top: 151px!important;}
</style>
<div style="position:fixed;z-index:9999;left:0;top:0;width:100%;height:70px;background-color:#e0e0e0;color:#396CA5;border-bottom:1px solid #cecece;text-align:center;line-height:70px;white-space: nowrap;overflow: hidden;text-overflow: ellipsis">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->

<div id="wrap">
    <header  style="position: absolute;" >
    <div id="site-meta">
        <a href="/" id="logo">
            <h1 class="title">黄龙天空</h1>
        </a>
        
        <h2 class="subtitle">技术博客</h2>
        
    </div>
    <ul id="nav">
        
            <li><a href="/"><i class="fa fa-home"></i>首页</a></li>
        
            <li><a href="/atom.xml"><i class="fa fa-rss"></i>RSS</a></li>
        
        <li id="search"><a href="javascript:void(0)"><i class="fa fa-search"></i>搜索</a></li>
    </ul>
</header>

    <div id="container">
        
<ul id="sidebar">
    
    
<li class="widget notification">
    <i class="fa fa-bell-o"></i>
    <div>
        
<p>一个普通python工程师的技术博客：<a href="https://github.com/huanglong123"
title="fork me" target="_blank">github</a></p>
    </div>
</li>

    
    
<li class="widget widget-normal category">
    <h3 class="fa fa-th widget-title">分类</h3>
    <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/python/"><i class="fa" aria-hidden="true">python</i></a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/常用命令/"><i class="fa" aria-hidden="true">常用命令</i></a><span class="category-list-count">2</span></li></ul>
</li>


    
    
<li class="widget widget-normal archive">
  <h3 class="fa fa-archive widget-title">归档</h3>
    <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/"><i class="fa" aria-hidden="true">May 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/03/"><i class="fa" aria-hidden="true">March 2017</i></a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/02/"><i class="fa" aria-hidden="true">February 2017</i></a><span class="archive-list-count">1</span></li></ul>
</li>


    
    
    
    
<li class="widget widget-normal tags">
  <h3 class="fa fa-tags widget-title">标签云</h3>
  <div class="tagcloud-content">
    
      <a href="/tags/python/" style="font-size: 0.14rem; color: #69c">python</a> <a href="/tags/git/" style="font-size: 0.14rem; color: #69c">git</a> <a href="/tags/linux/" style="font-size: 0.14rem; color: #69c">linux</a>
  </div>
</li>

    
    
<li class="widget widget-normal friends-link">
    <h3 class="fa fa-globe widget-title">友链</h3><br/>

    
        <a href="http://geekaholiclin.github.io" class="fa" target="_blank">主题作者</a>

    

</li>

    
</ul>


        <div id="main">
    <article id="post">
        <div id="post-header">

            <h1 id="list.sort 方法和内置sorted">
                
                list.sort 方法和内置sorted
                
            </h1>
            <div class="article-meta">
    
    
    <span class="categories-meta fa-wrap">
            <i class="fa fa-folder-open-o"></i>
        <span>python</span>
    </span>
    
    
    <span class="fa-wrap">
         <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            python
            
        </span>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta ">2017/05/16</span>
    </span>
    
    <span  class=" fa-wrap">
        <i class="fa fa-comment-o"></i>
        <span id="comments-count" class="comments-meta disqus-comment-count ds-thread-count comments" data-disqus-url="http://huanglongtiankong.oschina.io/2017/05/16/sorted/" data-thread-key="/2017/05/16/sorted/"
           data-count-type="comments"></span>
    </span>
    
    
    
</div>

            
            
        </div>
        
        <div id="post-body">
            <h1 id="list-sort-方法和内置sorted"><a href="#list-sort-方法和内置sorted" class="headerlink" title="list.sort 方法和内置sorted"></a>list.sort 方法和内置sorted</h1><p>与字面意思一样，这两个方法都是用于排序的，不同的是list.sort方法会就地排序列表，这个方法返回值是None，也就是不会给你返回一个新列表，而是把原有的list进行了排序。例子：</p>
<pre><code>&gt;&gt;&gt; s = [1,5,2,6,7,3,4]
&gt;&gt;&gt; s.sort()
&gt;&gt;&gt; s
[1, 2, 3, 4, 5, 6, 7]
</code></pre><p>sorted则会创建一个新的列表作为返回值。这个方法可以接受任何的可迭代对象，不过最后返回的都会是一个列表。例子：</p>
<pre><code>&gt;&gt;&gt; s = (1,5,2,6,7,3,4)
&gt;&gt;&gt; sorted(s)
[1, 2, 3, 4, 5, 6, 7]
</code></pre>
        </div>
        <div id="post-footer">
            <div class="avatar" >
                <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1488620979324&di=7aa4931b000db9f3503b1e274404b47b&imgtype=0&src=http%3A%2F%2Fwenwen.soso.com%2Fp%2F20100225%2F20100225220031-1089883172.jpg" alt="avatar"/>
                
                
                <a href="javascript:void(0)" class="donate fa">赠我一杯 &#128536;</a>
                
            </div>
            <ul class="author-profile-section">
                <li>作者:
                    
                    <a href="/about.html">黄龙天空</a>
                </li>
                <li>发表日期: <span>2017-05-16  10:47:05</span></li>
                
                <li>最后编辑日期: <span>2017-05-16  10:47:05</span></li>
                
                <li class="post-category">
                    文章分类:
                    
                    <a href="/categories/python/">python</a>
                    
                </li>
                <li class="post-tags">
                    文章标签:
                    
                    <a href="/tags/python/">python</a>
                    
                </li>
                
                <li> 版权声明: <a href="https://creativecommons.org/licenses/by-nc-nd/3.0/" target="_blank">
知识共享署名-非商业性使用-禁止演绎 3.0 未本地化版本许可协议（CC BY-NC-ND 3.0）
</a></li>
                
            </ul>
            <div id="donate-wrap">
                
                
                
                <img src="http://olb32qrq7.bkt.clouddn.com/alipay.jpg" alt="支付宝付款" class="donate-img">
                
                <img src="http://olb32qrq7.bkt.clouddn.com/wechat.png" alt="微信付款" class="donate-img">
                
                
            </div>
        </div>
    </article>
    <div class="article-nav">
        
        
        <a href="/2017/03/04/linux命令/" class="next-post fa">linux命令</a>
        
    </div>
    
    <div id="comments">
        



    </div>
    
</div>


    </div>
    <footer id="footer">
    
    <div class="social">
        
        <a href="https://www.example1.com" class="fa fa-free-code-camp" target="_blank" title="freecodecamp"></a>
        
        <a href="https://www.example2.com" class="fa fa-github" target="_blank" title="Follow me~"></a>
        
    </div>
    
    <div>
        
        <a href="/" class="copyright-links">黄龙天空</a>&copy;2015 - 2017.All Rights
        Reserved.
    </div>
    <p>Powered by <a href="https://hexo.io" class="copyright-links" target="_blank">Hexo</a> | Theme by <a
                href="https://github.com/GeekaholicLin" class="copyright-links" target="_blank">GeekaholicLin</a>
    </p>
    
    
    <p>
        <span id="busuanzi_container_site_uv" class="fa fa-bar-chart">
        欢迎第<span id="busuanzi_value_site_uv"><i class="fa fa-spinner fa-spin"></i></span>位小伙伴~
        </span>
    </p>
    
</footer>

</div>
    <ul id="tools">
    <li class="totop-btn fa fa-angle-up"></li>
    
    <li class="toc-btn fa fa-list-ul"></li>
    
    

    
</ul>
<p id="process"></p>
<div id="search-overlay">
    <div class="search-area-wrap">
        <div id="search-area">
            <div class="input-wrap focus">
                <i class="fa fa-search" aria-hidden="true"></i>
                <input id="search-input" autofocus autocomplete="off" type="text"
                       placeholder="search this website..."/>
            </div>
            <ul id="search-result">
                <li class="load-first"><i class="fa fa-spinner fa-spin"></i></li>
            </ul>
        </div>
    </div>
</div>

    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#list-sort-方法和内置sorted"><span class="toc-number">1.</span> <span class="toc-text">list.sort 方法和内置sorted</span></a></li></ol>




<script src="/js/search.js"></script>
<script type="text/javascript">
    //theme config datas
    var copyrightObj = {};
    copyrightObj.enable = 'true';
    copyrightObj.triggerCopyLength = '200';
    copyrightObj.appendText = '商业转载请联系作者获得授权,非商业转载请注明出处 © example';
    var leancloudObj = {};
    leancloudObj.enable = 'false';
    leancloudObj.className = 'BlogCounter';
    leancloudObj.limits = '10';
</script>
<script type="text/javascript">
    var search = {};
    var search_path = "search.xml";
    if (!search_path) {
        search_path = "search.xml";
    }
    search.path = "/" + search_path;
    search.func =  _ajax.init();
</script>
<script src="/js/app.js"></script>

</body>
</html>